package com.holiday.eshop.module.protocol;

import okhttp3.OkHttpClient;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * @author
 * @version 1.0
 * @date 2017/4/21
 */

public class ProtocolManager {

    private ProtocolManager mProtocolManager;
    private RetrofitService mRetrofitService;

    private ProtocolManager() {
        initRetrofit();
    }

    public RetrofitService getRetrofitService() {
        return mRetrofitService;
    }

    private static class SingleHolder {
        public static ProtocolManager instance = new ProtocolManager();
    }

    public static ProtocolManager getInstance() {

        return SingleHolder.instance;
    }


    private void initRetrofit() {
        OkHttpClient.Builder builder = new OkHttpClient.Builder();
//        if (LogUtil.mDebug) {
//            HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
//            interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
//            builder.addInterceptor(interceptor);
//        }

        Retrofit retrofit = new Retrofit.Builder().baseUrl(RetrofitService.HOST)
                                                  .addConverterFactory(GsonConverterFactory.create())
                                                  .client(builder.build())
                                                  .build();
        mRetrofitService = retrofit.create(RetrofitService.class);
    }
}
